package com.hmall.order.web;

import com.hmall.common.client.UserFeignClient;
import com.hmall.common.thread.User;
import com.hmall.common.thread.UserThreadLocal;
import com.hmall.order.pojo.Order;
import com.hmall.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private IOrderService orderService;

   @Autowired
   private UserFeignClient userFeignClient;

   @GetMapping("{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
      return orderService.getById(orderId);
   }

   /**
    * 测试拦截器和threadLocal
    */
   @GetMapping
   public void test(){
      User user = UserThreadLocal.getUser();
      System.out.println(user);

      //远程调用
      user = userFeignClient.getUser(user.getId());
      System.out.println(user);
   }
}
